home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / cxref-1.001 / cxref-1~ / cxref / query / query.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-24  |  3.8 KB  |  129 lines

  1. /***************************************
  2.   $Header: /home/amb/cxref/query/RCS/query.c 1.3 1996/02/24 14:53:51 amb Exp $
  3.  
  4.   C Cross Referencing & Documentation tool. Version 1.0
  5.   ******************/ /******************
  6.   Written by Andrew M. Bishop
  7.  
  8.   This file Copyright 1995,96 Andrew M. Bishop
  9.   It may be distributed under the GNU Public License, version 2, or
  10.   any higher version.  See section COPYING of the GNU Public license
  11.   for conditions under which this file may be redistributed.
  12.   ***************************************/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. #include "../memory.h"
  19. #include "../datatype.h"
  20. #include "../cxref.h"
  21. #include "query.h"
  22.  
  23. /*+ The command line switch that sets the amount of cross referencing to do. +*/
  24. int option_xref=0;
  25.  
  26. /*+ The command line switch for the output name, +*/
  27. char *option_odir=".",          /*+ The directory to use. +*/
  28.      *option_name="cxref";      /*+ The base part of the name. +*/
  29.  
  30. File *files=NULL;               /*+ The files that are queried. +*/
  31. int n_files=0;                  /*+ The number of files referenced. +*/
  32.  
  33. Function *functions=NULL;       /*+ The functions that are queried. +*/
  34. int n_functions=0;              /*+ The number of functions referenced. +*/
  35.  
  36. Variable *variables=NULL;       /*+ The variables that are queried. +*/
  37. int n_variables=0;              /*+ The number of variables referenced. +*/
  38.  
  39. Typedef *typedefs=NULL;         /*+ The type definitions that are queried. +*/
  40. int n_typedefs=0;               /*+ The number of typedefs referenced. +*/
  41.  
  42.  
  43. /*++++++++++++++++++++++++++++++++++++++
  44.   The main function that does it all.
  45.  
  46.   int main Returns the status, zero for normal termination, else an error.
  47.  
  48.   int argc The command line number of arguments.
  49.  
  50.   char** argv The actual command line arguments
  51.   ++++++++++++++++++++++++++++++++++++++*/
  52.  
  53. int main(int argc,char** argv)
  54. {
  55.  int i,args=0;
  56.  
  57.  if(argc==1)
  58.    {
  59.     fputs("Usage: cxref-query [name [ ... name]]                       ; Names of objects to query.\n"
  60.           "                   [-Odirname]                              ; Use dirname as the input directory\n"
  61.           "                   [-Nbasename]                             ; Use basename.* as the input filenames\n"
  62.           "                   [-xref[-all][-file][-func][-var][-type]] ; Use cross reference files (default -xref-all).\n"
  63.           ,stderr);
  64.     exit(1);
  65.    }
  66.  
  67.  for(i=1;i<argc;i++)
  68.    {
  69.     if(!strncmp(argv[i],"-O",2))
  70.       {option_odir=&argv[i][2]; argv[i]=NULL; continue;}
  71.  
  72.     if(!strncmp(argv[i],"-N",2))
  73.       {option_name=&argv[i][2]; argv[i]=NULL; continue;}
  74.  
  75.     if(!strncmp(argv[i],"-xref",5))
  76.       {
  77.        char* p=&argv[i][5];
  78.  
  79.        if(!*p)
  80.           option_xref=XREF_ALL;
  81.        else
  82.           while(*p)
  83.             {
  84.              if(!strncmp(p,"-all" ,4)) {option_xref|=XREF_ALL ; p=&p[4]; continue;}
  85.              if(!strncmp(p,"-file",5)) {option_xref|=XREF_FILE; p=&p[5]; continue;}
  86.              if(!strncmp(p,"-func",5)) {option_xref|=XREF_FUNC; p=&p[5]; continue;}
  87.              if(!strncmp(p,"-var" ,4)) {option_xref|=XREF_VAR ; p=&p[4]; continue;}
  88.              if(!strncmp(p,"-type",5)) {option_xref|=XREF_TYPE; p=&p[5]; continue;}
  89.              break;
  90.             }
  91.        argv[i]=NULL;continue;
  92.       }
  93.  
  94.     args++;
  95.     if(!strncmp(argv[i],"./",2))
  96.        argv[i]+=2;
  97.    }
  98.  
  99.  LoadInCrossRefs();
  100.  
  101.  if(args)
  102.    {
  103.     for(i=1;i<argc;i++)
  104.        if(argv[i])
  105.          {
  106.           printf("cxref-query> %s\n\n",argv[i]);
  107.           OutputCrossRef(argv[i]);
  108.          }
  109.    }
  110.  else
  111.    {
  112.     while(1)
  113.       {
  114.        char input[128];
  115.        printf("cxref-query> ");
  116.        if(!fgets(input,128,stdin))
  117.          {printf("\n\n");break;}
  118.  
  119.        printf("\n");
  120.        input[strlen(input)-1]=0;
  121.        OutputCrossRef(input);
  122.       }
  123.    }
  124.  
  125.  PrintMemoryStatistics();
  126.  
  127.  return(0);
  128. }
  129.